package edu.sju.chenshu.system.controller.question;

import edu.sju.chenshu.common.core.domain.Result;
import edu.sju.chenshu.common.core.domain.TableDataInfo;
import edu.sju.chenshu.system.domain.question.dto.QuestionEditDTO;
import edu.sju.chenshu.system.domain.question.dto.QuestionQueryDTO;
import edu.sju.chenshu.system.domain.question.dto.QuestionAddDTO;
import edu.sju.chenshu.system.domain.question.vo.QuestionDetailVO;
import edu.sju.chenshu.system.service.question.IQuestionService;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/question")
@Tag(name = "题目管理API")
public class QuestionController {

    @Autowired
    IQuestionService questionService;

    @GetMapping("/list")
    public TableDataInfo list(QuestionQueryDTO questionQueryDTO) {
        return questionService.list(questionQueryDTO);
    }

    @PostMapping("/add")
    public Result<Void> add(@Valid @RequestBody QuestionAddDTO questionSaveDTO) {
        return questionService.add(questionSaveDTO);
    }

    @GetMapping("/detail")
    public Result<QuestionDetailVO> detail(Long questionId) {
        return Result.ok(questionService.detail(questionId));
    }

    @PutMapping("/edit")
    public Result<Void> edit(@Valid @RequestBody QuestionEditDTO questionEditDTO) {
        return questionService.edit(questionEditDTO);
    }

    @DeleteMapping("/delete")
    public Result<Void> delete(@RequestParam Long questionId) {
        return questionService.delete(questionId);
    }
}
